Conversation
…ive Subscription exists
… Expired Subscription exists
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-junit-jupiter</artifactId> | ||
| <version>4.11.0</version> |
There was a problem hiding this comment.
а не должен совпадать с junit 5 версией?
|
|
||
| class SubscriptionDaoIT extends IntegrationTestBase { | ||
|
|
||
| private final SubscriptionDao subDao = SubscriptionDao.getInstance(); |
There was a problem hiding this comment.
Лучше использовать общепринятые сокращения в именовании всего в Java (sub).
| Subscription sub3 = subDao.insert(getSubscription("User 3", 3)); | ||
|
|
||
| List<Subscription> actualSub = subDao.findAll(); | ||
| List<Integer> userIds = actualSub.stream().map(Subscription::getUserId).toList(); |
There was a problem hiding this comment.
разделяй четко 3 секции в тесте, чтобы улучшить его читабильность: given/when/then
| @Test | ||
| void whenSubExists_thenItIsDeleted() { | ||
| Subscription savedSub = subDao.insert(getSubscription("User 1", 1)); | ||
| boolean isDeleted = subDao.delete(savedSub.getId()); |
There was a problem hiding this comment.
is* больше относится к именованию методов, а не локальных переменных
для переменных не нужны эти префиксы
| void findByUserId() { | ||
| Subscription expectedSub = subDao.insert(getSubscription("User 1", 1)); | ||
|
|
||
| List<Subscription> actualSubs = subDao.findByUserId(expectedSub.getUserId()); |
There was a problem hiding this comment.
Для теста метода findByUserId нужна вставить несколько подписок с разным userId - иначе некорректный dataset. Его можно заменить на findAll, например, и он все еще будет проходить
| @Mock | ||
| private CreateSubscriptionValidator createSubValidator; | ||
| @Mock | ||
| private Clock clock = Clock.fixed(Instant.now(), ZoneId.systemDefault()); |
| private SubscriptionService subService; // ); | ||
|
|
||
| @Test | ||
| void whenSubscriptionExists_thenUpdateAndInsert() { |
There was a problem hiding this comment.
не может сразу и обновить и вставить метод
Плохое название тестового метода - не говорит что именно тестируется в нем
| void whenSubIsActive_thenExceptionThrown() { | ||
| doReturn(Optional.of(Subscription.builder().status(Status.EXPIRED).build())) | ||
| .when(subDao).findById(anyInt()); | ||
| assertThrows(SubscriptionException.class, () -> subService.cancel(anyInt())); |
There was a problem hiding this comment.
Нужно проверить какое именно исключение упало, например, код/текст исключения и т.д. Иначе причина может поменяться, а тест будет проходить
| import java.time.format.DateTimeFormatter; | ||
| import java.util.Locale; | ||
|
|
||
| public class DateUtil { |
There was a problem hiding this comment.
если это утилитный класс - то final класс и private консторуктор
| assertThat(actualResult.hasErrors()).isTrue(); | ||
| assertThat(actualResult.getErrors().size()).isEqualTo(1); | ||
| assertThat(actualResult.getErrors().get(0).getCode()).isEqualTo(102); | ||
| assertThat(actualResult.getErrors().get(0).getMessage()).isEqualTo("provider is invalid"); |
There was a problem hiding this comment.
можно просто получить объект ошибки и проверять объект, вместо множества ассертов
No description provided.